<?php
//
// +------------------------------------------------------------------------+
// | Gecko Framework                                                        |
// +------------------------------------------------------------------------+
//
require_once("Gecko/Form/Exception.php");
require_once("Gecko/Form/Field.php");
require_once("Gecko/DataSource/Select/DBTable.php");

/**
 * Select control with a DBTable Source (autobind)
 *
 * @package Gecko.Form.Field;
 * @author Christopher Valderrama <valderrama.christopher@gmail.com>
 * @copyright Copyright (c) 2008
 * @version $Id$v1.0$ 2008
 * @access public
 **/
class Gecko_Form_Field_SelectDbTable extends Gecko_Form_Field_Select {
	/**
	 * Creates a new select control, you must submit a
	 * Zend_Db_Table Instance, and a method to call to fill
	 * data, this settings must be in the $params array
	 *
	 * @param string $name
	 * @param string $value
	 * @param array $params
	 */
	public function __construct( $name, $value = "", $params = array() ) {
		$table = (isset( $params['table'] ) ? $params['table'] : null );
		$method = (isset( $params['method'] ) ? $params['method'] : null );

		if( !( $table instanceof Zend_Db_Table_Abstract ) ) {
			throw new Gecko_Form_Exception( '$table isn\'t a instance of Zend_Db_Table_Abstract' );
		}

		if( !$method ) {
			throw new Gecko_Form_Exception( '$method not set' );
		}

		$source = new Gecko_DataSource_Select_DBTable( $table, $method );
		$this->setSource( $source );

		parent::__construct( $name, $value, $params );
	}
}